package com.example.controller;

import com.example.mapper.DivisionAssetInfoMapper;
import com.example.studyFile.QRcode.QRBarCodeWebUtil;
import com.example.work.check.AssetComparisonService;
import com.example.work.check.AssetImportService;
import com.example.work.check.ComparisonResult;
import com.example.work.entiy.DivisionAssetInfoWithIpPorts;
import com.example.work.mapper.AssetDatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.reactive.function.client.WebClient;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by Administrator on 2018/11/8 0008.
 * 系统控制器层
 */
@Controller
public class SystemController {
    @Autowired
    private AssetDatabaseService assetDatabaseService;


    /**
     * 生成二维码图片
     * 1。通过网页访问：http://localhost:8080/index.html
     *      填入内容生成二维码。
     * 2.访问：http://localhost:8080/coco/qrCode?codeContent=拼接的字符串
     *      直接返回二维码
     *
     * @param codeContent 需要生成的二维码字符串
     * @param response  servlet的响应，直接以流的形式显示在网页上。
     */
    @GetMapping("coco/qrCode")
    public void getQRCode(String codeContent, HttpServletResponse response) {
        System.out.println("codeContent=" + codeContent);
        try {
            /**
             * 调用工具类生成二维码并输出到输出流中
             */
            QRBarCodeWebUtil.createCodeToOutputStream(codeContent, response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




    @Autowired
    private AssetImportService importService;



    @GetMapping("importService")
    public void importServiceTWO() {
        String excelDirectory = "D:\\tool\\duibi";

        try {
        // 导入Excel数据
            importService.importFromDirectory(excelDirectory);




        // 执行数据比对
            ComparisonResult result = importService.compareWithDatabase();


            System.out.println("对比结束");
//            assetDatabaseService.insertAssetsToDatabase( result);


            // 查看比对结果
//            System.out.println(result.generateDetailedReport());

            System.out.println("资产列表数量统计:");
            System.out.println("数据库: " + importService.getAssetEntities().size());


        } catch (Exception e) {
            e.printStackTrace();
        }
    }




}